/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vera.hibernate.dao;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import vera.hibernate.entity.BillReceiptLinks;
import vera.hibernate.util.HibernateUtil;

/**
 *
 * @author vgncr35g
 */
public class BillReceiptLinksDAO extends EntityDAO {
    public BillReceiptLinksDAO()
    {
        
    }
    
    public BillReceiptLinks getBillReceiptLink(int billNum, int receiptNum)
    {
        Session s = HibernateUtil.openSession();
        Query q = s.getNamedQuery("getBillReceiptLink");
        q.setInteger("billNum", billNum);
        q.setInteger("receiptNum", receiptNum);
        BillReceiptLinks billReceiptLinks = (BillReceiptLinks) q.uniqueResult();
        s.close();
        return billReceiptLinks;
    }
    
    public List<BillReceiptLinks> getBillReceiptLinkByBillNum(int billNum)
    {
        Session s = HibernateUtil.openSession();
        Query q = s.getNamedQuery("getBillReceiptLinkByBillNum");
        q.setInteger("billNum", billNum);
        List<BillReceiptLinks> billReceiptLinks = q.list();
        s.close();
        return billReceiptLinks;
    }
    
    public List<BillReceiptLinks> getBillReceiptLinkByReceiptNum(int receiptNum)
    {
        Session s = HibernateUtil.openSession();
        Query q = s.getNamedQuery("getBillReceiptLinkByReceiptNum");
        q.setInteger("receiptNum", receiptNum);
        List<BillReceiptLinks> billReceiptLinks = q.list();
        s.close();
        return billReceiptLinks;
    }
    
    public void deleteBillReceiptLinks(int billNum, int receiptNum)
    {
        deleteEntity(getBillReceiptLink(billNum, receiptNum));
    }
    
    public void deleteLinksByBillNum(int billNum)
    {
        List<BillReceiptLinks> billReceiptLinks = getBillReceiptLinkByBillNum(billNum);
        for(BillReceiptLinks blr : billReceiptLinks)
        {
            deleteEntity(blr);
        }
    }
    
    public void deleteLinksByReceiptNum(int receiptNum)
    {
        List<BillReceiptLinks> billReceiptLinks = getBillReceiptLinkByReceiptNum(receiptNum);
        for(BillReceiptLinks blr : billReceiptLinks)
        {
            deleteEntity(blr);
        }
    }
}
